<template>
    <div>
        <Row style="margin:5px 0px 10px 5px" >
            <i-col span="2" >
                <Button  size="default"  type="primary" @click="btn_refresh">刷新</Button>
            </i-col>
		</Row>
        <i-table size="default"   border stripe :columns="format" :data="show_list" height="720"></i-table >
        <div style="text-align: center;margin-top: 10px;">
            <Page :total="total" :page-size="pageSize"  @on-change="changePage" show-total/>
        </div>
    </div>
</template>

<script>

import { get_storageclass_list} from  '@/api'
import {k8s_cluster_post} from '@/api/http'
import { get_placement } from '@/common/util'
import store from '@/store'

export default {
    data() {
        return {
            sharedState: store.state,
            format: [
                {
                    title: '名字',key: 'name',width: 300,

                },
                {
                    title: '提供者',key: 'provisioner'
                },
                {
                    title: 'reclaim策略',key: 'reclaim_policy'
                },
                {
                    title: '参数',key: 'parameters',
                    render : (h,params) => {
                        let parameters = params.row.parameters 
                        if (parameters == null ){
                            return   h('p','无')
                        }else{
                            let value = JSON.stringify(parameters,undefined,4)
                            let placement = get_placement(params)
                            return h('Poptip', {props:{'trigger':'hover','word-wrap':true,'placement':placement,content:value}},[
                                    h('a', '显示')
                            ]);

                        }
                    }
                },
                {
                    title: '卷绑定模式',key: 'volume_binding_mode',
                },
                {
                    title: 'mount参数',key: 'mount_options',
                },
                {
                    title: '创建时间',key: 'create_time',
                },

            ],
            // 分页
            total_list: [],
            show_list: [],
            total: 0,
            pageSize: 10,
        }
    },
    methods: {
        btn_refresh(){
            this.refresh()
        },
        changePage(index) {
            let _start = (index -1) * this.pageSize
            let _end = index * this.pageSize
            this.show_list = this.total_list.slice(_start,_end)
        },
        refresh() {
            k8s_cluster_post(get_storageclass_list).then( (response) => {
                this.total_list = response.data
                this.total = response.data.length
                if(this.total < this.pageSize) {
                    this.show_list = this.total_list
                }else {
                    let currentPage = this.$refs.page.currentPage
                    let _start = (currentPage-1) * this.pageSize
                    let _end = currentPage * this.pageSize
                    this.show_list = this.total_list.slice(_start,_end)
                }
            })
        }
    },
    mounted: function() {
        setTimeout(() =>{
            this.refresh();
        },400); 
    }
}
</script>
<style scoped>

</style>